package proyecto.testcasetool.presentation.editor.pages;


import java.util.List;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.editor.FormEditor;


public class MDFormPageUseCase extends AbstractMDFormPage {

	/**
	 * The page ID
	 */
	public static final String PAGE_ID = "usecase-master-detail"; //$NON-NLS-1$

	/**
	 * @param editor
	 *            the form editor in which this page will be included
	 */
	public MDFormPageUseCase(FormEditor editor, String pageTitle) {
		super(editor, pageTitle, PAGE_ID);
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.eef.runtime.ui.editors.pages.AbstractMDFormPage#createMasterDetailsBlock()
	 */
	@Override
	protected AbstractMasterDetailsBlock createMasterDetailsBlock() {
		MasterDetailsBlockUseCase block = new MasterDetailsBlockUseCase() {

			/**
			 * {@inheritDoc}
			 * 
			 * @see org.eclipse.emf.eef.runtime.ui.widgets.masterdetails.AbstractEEFMasterDetailsBlock#additionalPageActions()
			 */
			protected List<Action> additionalPageActions() {
				return MDFormPageUseCase.this.additionalPageUserActions();
			}

		};
		block.setInitialMasterPartToolBarVisibility(initialMasterPartToolBarVisibility);
		return block;
	}
	
	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.ui.forms.editor.FormPage#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
	public void createPartControl(Composite parent) {
		super.createPartControl(parent);
		getModelViewer().addSelectionChangedListener(
				new ISelectionChangedListener() {
					// This just notifies those things that
					// are affected by the selection.
					//
					public void selectionChanged(
							SelectionChangedEvent selectionChangedEvent) {
						((ISelectionProvider) getEditor()).setSelection(selectionChangedEvent
								.getSelection());
					}
				}

		);
	}

}
